package crossbreed.factories;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;

import crossbreed.views.Controls.LineNumberPanel;

public class MergeFactory
{
	public JFrame createMerge()
	{
		JPanel diffOverview = new JPanel();
		diffOverview.setPreferredSize(new Dimension(40, 1));
		
		JTextPane theirs = new JTextPane();
		JTextPane original = new JTextPane();
		JTextPane yours = new JTextPane();		
		
		JPanel theirPanel = new JPanel();
		theirPanel.setLayout(new BorderLayout());
		theirPanel.add(theirs, BorderLayout.CENTER);
		theirPanel.add(new LineNumberPanel(theirs), BorderLayout.WEST);
		
		JPanel yourPanel = new JPanel();
		yourPanel.setLayout(new BorderLayout());
		yourPanel.add(yours, BorderLayout.CENTER);
		yourPanel.add(new LineNumberPanel(yours), BorderLayout.WEST);
		
		JPanel originalPanel = new JPanel();
		originalPanel.setLayout(new BorderLayout());
		originalPanel.add(original, BorderLayout.CENTER);
		originalPanel.add(new LineNumberPanel(original), BorderLayout.WEST);
				
		JScrollPane scrollPaneTheirs = new JScrollPane(theirPanel);
		JScrollPane scrollPaneOriginal = new JScrollPane(originalPanel);
		JScrollPane scrollPaneYours = new JScrollPane(yourPanel);

		JSplitPane theirSplitPane = new JSplitPane();
		theirSplitPane.setDividerLocation(0.5);
		theirSplitPane.setDividerSize(8);
		
		JSplitPane originalAndYourSplitPane = new JSplitPane();
		originalAndYourSplitPane.setDividerLocation(0.5);
		originalAndYourSplitPane.setDividerSize(8);

		theirSplitPane.setLeftComponent(scrollPaneTheirs);
		theirSplitPane.setRightComponent(originalAndYourSplitPane);
		originalAndYourSplitPane.setLeftComponent(scrollPaneOriginal);
		originalAndYourSplitPane.setRightComponent(scrollPaneYours);
		
		JLabel statusBar = new JLabel();
		statusBar.setPreferredSize(new Dimension(100, 18));

		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		panel.add(theirSplitPane);
		panel.add(diffOverview, BorderLayout.LINE_START);
		panel.add(statusBar, BorderLayout.SOUTH);

		JMenuBar bar = new JMenuBar();
		bar.add(new JMenu("File"));
		bar.add(new JMenu("Edit"));
		bar.add(new JMenu("Help"));

		JFrame frame = new JFrame();
		frame.setTitle("3-Way Merge");
		frame.setExtendedState(Frame.MAXIMIZED_BOTH);
		frame.add(panel);
		frame.setJMenuBar(bar);
		
		return frame;
	}
}
